package controllers

import (
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
	"iris_product/repositories"
	"iris_product/services"
)

type OrderController struct {
	Ctx iris.Context
	OrderService services.IOrderService
	BaseController
}

// 注册service
func (o *OrderController) RegisterService() {
	orderRepository := repositories.NewOrderManager("order",o.Db)
	orderService := services.NewOrderService(orderRepository)
	o.MvcApp.Register(orderService)
}


func (o *OrderController) GetAll() mvc.View {
	orderList, err := o.OrderService.GetOrderAll()
	if err != nil {
		o.Ctx.Application().Logger().Error("获取订单列表失败:" + err.Error())
	}
	//fmt.Printf("%s",orderList)
	//fmt.Println(orderList[0].OrderStatus)
	return mvc.View{
		Name: "order/view.html",
		Data: iris.Map{
			"orderList":orderList,
		},
	}
}